package com.ss.android.article.browser.view.scrollwebview;

import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.webkit.WebView;

import inline.ScreenshotListener;

public final class BrowserWebView extends WebView {
    public BrowserWebView(Context context) {
        super(context);
    }

    static class SavedState extends View.BaseSavedState {
        public static final Parcelable.Creator CREATOR = new b();
        int prevScrollY;
        int scrollY;

        SavedState(Parcelable arg1) {
            super(arg1);
        }

        private SavedState(Parcel arg2) {
            super(arg2);
            this.prevScrollY = arg2.readInt();
            this.scrollY = arg2.readInt();
        }

        SavedState(Parcel arg1, a arg2) {
            this(arg1);
        }

        public void writeToParcel(Parcel arg2, int arg3) {
            super.writeToParcel(arg2, arg3);
            arg2.writeInt(this.prevScrollY);
            arg2.writeInt(this.scrollY);
        }
    }

    private int a;
    private int b;
    private ScreenshotListener c;
    private boolean d;
    private boolean e;
    private MotionEvent f;
    private ViewGroup g;

    private boolean a() {
        boolean v0 = this.c == null ? true : false;
        return v0;
    }

    public final int getCurrentScrollY() {
        return this.b;
    }

    public final boolean onInterceptTouchEvent(MotionEvent arg2) {
        boolean v0;
        if (this.a()) {
            v0 = super.onInterceptTouchEvent(arg2);
        } else {
            switch (arg2.getActionMasked()) {
                case 0: {
                    this.d = true;
                    break;
                }
            }

            v0 = super.onInterceptTouchEvent(arg2);
        }

        return v0;
    }

    public final void onRestoreInstanceState(Parcelable arg2) {
        this.a = ((SavedState) arg2).prevScrollY;
        this.b = ((SavedState) arg2).scrollY;
        super.onRestoreInstanceState(((SavedState) arg2).getSuperState());
    }

    public final Parcelable onSaveInstanceState() {
        SavedState v1 = new SavedState(super.onSaveInstanceState());
        v1.prevScrollY = this.a;
        v1.scrollY = this.b;
        return ((Parcelable) v1);
    }

    protected final void onScrollChanged(int arg2, int arg3, int arg4, int arg5) {
        super.onScrollChanged(arg2, arg3, arg4, arg5);
        if (!this.a()) {
            this.b = arg3;
            if (this.d) {
                this.d = false;
            }

            this.a = arg3;
        }
    }

    public final boolean onTouchEvent(MotionEvent arg8) {
        ViewGroup v1_1;
        boolean v0;
        float v3 = 0f;
        if (this.a()) {
            v0 = super.onTouchEvent(arg8);
        } else {
            switch (arg8.getActionMasked()) {
                case 2: {
                    if (this.f == null) {
                        this.f = arg8;
                    }

                    float v0_1 = arg8.getY() - this.f.getY();
                    this.f = MotionEvent.obtainNoHistory(arg8);
                    if ((((float) this.getCurrentScrollY())) - v0_1 > 0f) {
                        return super.onTouchEvent(arg8);
                    }

                    if (this.e) {
                        return false;
                    }

                    if (this.g == null) {
                        v1_1 = (ViewGroup) this.getParent();
                    } else {
                        v1_1 = this.g;
                    }

                    BrowserWebView v0_2 = this;
                    float v4 = 0f;
                    while (v0_2 != null) {
                        if ((((ViewParent) v0_2)) == (((ViewParent) v1_1))) {
                            break;
                        }

                        v4 += ((float) (((View) v0_2).getLeft() - ((View) v0_2).getScrollX()));
                        v3 += ((float) (((View) v0_2).getTop() - ((View) v0_2).getScrollY()));
                        ViewParent v0_3 = ((View) v0_2).getParent();
                    }

                    MotionEvent v0_4 = MotionEvent.obtainNoHistory(arg8);
                    v0_4.offsetLocation(v4, v3);
                    if (v1_1.onInterceptTouchEvent(v0_4)) {
                        this.e = true;
                        v0_4.setAction(0);
                        this.post(new a(v1_1, v0_4));
                        return false;
                    }

                    return super.onTouchEvent(arg8);
                }
                case 1:
                case 3: {
                    this.e = false;
                    break;
                }
            }
            v0 = super.onTouchEvent(arg8);
        }

        return v0;
    }

    public final void setScrollViewCallbacks$1d03b6e1(ScreenshotListener arg1) {
        this.c = arg1;
    }

    public final void setTouchInterceptionViewGroup(ViewGroup arg1) {
        this.g = arg1;
    }
}

